<?php

class T4Templater
{
protected static $smarty;

/**
 * get Smarty template engine instance
 * @return unknown_type
 */
public static function getSmarty()
	{
	if(!isset(self::$smarty))
		{
		$aPathInfo = pathinfo(__FILE__);
		$sTemplaterPath = $aPathInfo['dirname'];
		require_once($sTemplaterPath."/smarty/Smarty.class.php");
		$smarty = new Smarty;
		$smarty->template_dir = X4_TPL_DIR;
		$smarty->compile_dir = X4_TEMP_DIR."/templates_c";
		$smarty->plugins_dir []= $sTemplaterPath."/extensions";
    	//$smarty->config_dir = 'C:/PHP/smarty/configs/';
    	//$smarty->cache_dir = 'C:/PHP/smarty/cache/';
    	//$smarty->force_compile = true;
    	//$smarty->caching=0;
		self::$smarty = $smarty;
		}
	return self::$smarty;
	}

protected static $quicky;

/**
 * get Quicky template engine instance
 * @return Quicky
 */
public static function getQuicky()
	{
	if(!isset(self::$quicky))
		{
		$aPathInfo = pathinfo(__FILE__);
		$sTemplaterPath = $aPathInfo['dirname'];
		require_once($sTemplaterPath."/quicky/Quicky.class.php");
		$quicky = new Quicky;
		$quicky->template_dir = X4_TPL_DIR;
		$quicky->compile_dir = X4_TEMP_DIR."/templates_c/";
		$quicky->plugins_dir []= $sTemplaterPath."/extensions/";
    	//$smarty->config_dir = 'C:/PHP/smarty/configs/';
    	//$smarty->cache_dir = 'C:/PHP/smarty/cache/';
    	//$smarty->force_compile = true;
    	//$smarty->caching=0;
		self::$quicky = $quicky;
		}
	return self::$quicky;
	}
		
public static function Template($sTemplate,$aData)
	{
	// TODO: FIX: Run template from X4 to initialize $X4 tpl var
	//$engine = self::getSmarty();
	$engine = self::getQuicky();
	$aDataBackup = array();
	foreach($aData as $sDataKey=>$mDataValue)
		if(array_key_exists($sDataKey,$engine->_tpl_vars) and $sDataKey!="X4")
			$aDataBackup[$sDataKey] = $engine->get_templates_vars($sDataKey);
	$engine->assign($aData);
	$result = $engine->fetch($sTemplate);
	$engine->assign($aDataBackup);
	return $result;
	}
}

?>